package cn.fz.mpdemo.controller;

import cn.fz.mpdemo.domain.vo.ResultVO;
import cn.fz.mpdemo.utils.UploadUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@Slf4j
@RestController
@Tag(name = "文件上传接口")
public class UploadController {
    @Operation(summary = "上传文件接口")
    @PostMapping("/upload")
    public ResultVO upload(@RequestParam("file") MultipartFile file) {
        log.info("文件上传, 文件名: {}", file.getOriginalFilename());
        String filePath = "/home/ke666/my_codes/my_upload/";
        Map<String,String> map = null;
        try {
            map = UploadUtils.upload(file,filePath);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return ResultVO.success(map);
    }
}
